package com.fancy.learncenter.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Hyy on 2017/1/6.
 */

public class FragPagerAdapter extends FragmentPagerAdapter {

    private List fragments;
    private List<String> tabTitles;


    public FragPagerAdapter(FragmentManager fm, List fragments, List<String> tabTitles) {
        super(fm);
        this.fragments = fragments;
        this.tabTitles = tabTitles;
    }

    public FragPagerAdapter(FragmentManager fm, List fragments) {
        super(fm);
        this.fragments = fragments;
        tabTitles = new ArrayList<>();
        for (int i = 0; i < fragments.size(); i++) {
            tabTitles.add("");

        }
    }

    public Fragment currentFragment;

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        currentFragment = (Fragment) object;
        super.setPrimaryItem(container, position, object);
    }


    @Override
    public Fragment getItem(int position) {
        return (Fragment) fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabTitles.get(position);
    }
}
